package com.neu.questionnaire_system.controller;


import com.neu.questionnaire_system.beans.ResponseEntity;
import com.neu.questionnaire_system.entity.Cluster;
import com.neu.questionnaire_system.mapper.ClusterMapper;
import com.neu.questionnaire_system.service.ClusterService;
import com.neu.questionnaire_system.service.impl.ClusterServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xingle
 * @since 2022-10-31
 */
@RestController
@CrossOrigin
@RequestMapping("/cluster")
public class ClusterController {

    @Autowired
    private ClusterServiceImpl clusterService;

    @RequestMapping("/insertCluster")
    public ResponseEntity insertCluster(String kind, String uid){
        return clusterService.insertCluster(kind, uid);
    }

    @RequestMapping("/showCluster")
    public ResponseEntity showCluster(){
        return clusterService.showCluster();
    }

    @RequestMapping("/deleteCluster")
    public ResponseEntity deleteGroup(String cid){
        return clusterService.deleteCluster(cid);
    }

    @RequestMapping("/findCluster")
    public ResponseEntity findClusterByKind(String kind,String uid){
        return clusterService.findClusterByKind(kind,uid);
    }

    /**
     * created by libo 根据提供的uid来查询当前用户下的群组信息
     * @param uid 提供当前用户的uid
     * @return 返回封装群组列表内容的对象
     */
    @RequestMapping("/showByUid")
    public ResponseEntity showClusterByUid(String uid){
        return clusterService.showClusterByUid(uid);
    }

    /**
     * created by libo 当前用户修改群组信息
     * @param map 提供群组的uid
     * @return 返回统一的对象
     */
    @RequestMapping("/updateCluster")
    public ResponseEntity updateCluster(@RequestBody Map<String,Object> map){
        return clusterService.updateCluster(map);
    }


    /**
     * created by jyh 用户添加答者
     * @param map 接收到的data，json格式
     * @return 返回封装的对象
     */
    @RequestMapping(value = "/addAnswer_Cluster")
    public ResponseEntity addAnswer(@RequestBody Map<String,Object> map) throws InvocationTargetException, IllegalAccessException {
        return clusterService.addAnswer_Cluster(map);
    }
    /**
     * created by jyh控制层接收一个包含键值对的map。用来查询答者
     * @param map 接收到的data，
     * @return 返回封装状态信息和内容的对象
     */
    @RequestMapping("/showAnswer_Cluster")
    public ResponseEntity showAnswer_Cluster(@RequestBody Map<String,Object> map){
        return clusterService.showAnswer_Cluster(map);
    }
    /**
     * created by jyh 当前用户删除答者
     * @param map 需要删除的答者的答者名
     * @return 返回封装状态信息和内容的对象
     */
    @RequestMapping("/deleteAnswer_Cluster")
    public ResponseEntity deleteAnswer(@RequestBody Map<String,Object> map){
        return clusterService.deleteAnswer_Cluster(map);
    }

    /**
     * created by jyh 用户查答者，请求地址
     * @param map 传入的map包含answerName
     * @return 返回包含查询到用户信息的对象，包含userName、password、phone
     */
    @RequestMapping("/findAidByAnswerName")
    public ResponseEntity findAnswerByAnswerName(@RequestBody Map<String,Object> map){
        return clusterService.findAidByAnswerName(map);
    }

    /**
     * created by libo 个性化组卷返回前端群组kind
     * @param map 包含用户uid
     * @return 统一对象
     */
    @RequestMapping("/shownoGroup")
    public ResponseEntity selectClusterByUid(@RequestBody Map<String,Object> map){
        return clusterService.showGroupByUid(map);
    }

}
